package com.lb.activity.sys.controller;

import com.lb.activity.po.VacTask;
import com.lb.activity.po.Vacation;
import com.lb.activity.sys.service.VacationService;
import com.lb.activity.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 001030
 */
@RestController
public class VacationController {

    @Autowired
    private VacationService vacationService;

    /**
     * 请假页面
     * @return
     */
    @GetMapping("qingjia")
    public ModelAndView qingjia(){
        return new ModelAndView("qingjia/qingjia");
    }

    /**
     * 请假申请Add页面
     * @return
     */
    @GetMapping("qingjiaAdd")
    public ModelAndView qingjiaAdd(){
        return new ModelAndView("qingjia/qingjia-add");
    }


    /**
     * 请假
     * @return
     */
    @PostMapping("apply")
    public ResultUtil apply(Vacation vacation, HttpServletRequest request){
        vacationService.startVacation(request,vacation);
        return ResultUtil.ok("提交成功");
    }

    /**
     * 我的申请
     * @param request
     * @return
     */
    @GetMapping("myVac")
    public Object myVac(HttpServletRequest request,Long type,Integer page,Integer limit){
        Object object = null;
        if(type == null || type == 0){
            object = vacationService.myVacation(request,page,limit);
        }else if(type == 1){
            object = vacationService.myApproveVacation(request,page,limit);
        }else if(type == 9){
            object = vacationService.myHistoryVacation(request,page,limit);
        }
        return object;
    }

    /**
     * 审批页面
     * @return
     */
    @GetMapping("examine")
    public ModelAndView examine(String taskId,HttpServletRequest request){
        ModelAndView modelAndView = new ModelAndView();
        //查询任务，回显
        VacTask vacTask = vacationService.viewVacation(taskId,request);
        if(vacTask != null){
            modelAndView.setViewName("qingjia/qingjia-examine");
            modelAndView.addObject("vacTask",vacTask);
        }else{
            modelAndView.setViewName("redirect:/qingjia");
        }
        return modelAndView;
    }

    /**
     * 审批
     * @param vacTask
     * @param request
     * @return
     */
    @PostMapping("passAudit")
    public Object passAudit(VacTask vacTask,HttpServletRequest request){
        Object object = vacationService.passVacation(vacTask,request);
        return object;
    }

/*
     *//**
     * 我的申请记录
     * @param request
     * @return
     *//*
    @GetMapping("myVacHistory")
    public Object myVacHistory(HttpServletRequest request){
        Object object = vacationService.myHistoryVacation(request);
        return object;
    }

    *//**
     * 待审批
     * @param request
     * @return
     *//*
    @GetMapping("myApprove")
    public Object myApprove(HttpServletRequest request){
        Object object = vacationService.myApproveVacation(request);
        return object;
    }*/


}
